package leetcode.每日一题;

import org.junit.Test;

/**
 * @author ：zsy
 * @date ：Created 2022/12/15 9:27 AM
 * @description：
 */
public class 字符串转化后的各位数字之和 {
    @Test
    public void test() {
        System.out.println(new Solution().getLucky("leetcode", 2));
    }

    class Solution {
        public int getLucky(String s, int k) {
            int sum = 0;
            for (int i = 0; i < s.length(); i++) {
                int idx = s.charAt(i) - 'a' + 1;
                sum += idx / 10 + idx % 10;
            }
            k--;
            while (k > 0) {
                k--;
                int cur = sum;
                sum = 0;
                while (cur > 0) {
                    sum += cur % 10;
                    cur /= 10;
                }
            }
            return sum;
        }
    }
}
